//
//  JPayHeadView.m
//  HeadIndustry
//
//  Created by jun on 2017/9/5.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JPayHeadView.h"

@interface JPayHeadView()

@property (nonatomic, strong) YYLabel *nameLa;
@property (nonatomic, strong) YYLabel *phoneLa;
@property (nonatomic, strong) YYLabel *addressLa;
//@property (nonatomic, strong) CALayer *addLayer;

@end

@implementation JPayHeadView

- (instancetype)initWithFrame:(CGRect)frame isHaveTap:(BOOL)isHaveTap
{
    if (self = [super initWithFrame:frame]) {
        _isHaveTap = isHaveTap;
        self.backgroundColor = [UIColor whiteColor];
        self.opaque = NO;
        [self setUpView];
    }
    return  self;
}

- (void)setUpView {
    YYLabel *titleLabel = [YYLabel new];
    titleLabel.text = @"收货人:";
    titleLabel.font = kFONT_TITLE(16);
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.left = 15;
    titleLabel.top = 10;
    titleLabel.size = CGSizeMake(75, 20);
    titleLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:titleLabel];
    
    YYLabel *name = [YYLabel new];
    name.font = kFONT_TITLE(16);
    name.textColor = [UIColor blackColor];
    name.left = titleLabel.right + 5;
    name.top = 10;
    name.size = CGSizeMake(kWindowW - 90 - 100, 20);
    [self addSubview:name];
    _nameLa = name;
    
    YYLabel *phone = [YYLabel new];
    phone.font = kFONT_TITLE(16);
    phone.textColor = [UIColor blackColor];
    phone.left = kWindowW - 120 - 30 - 15;
    phone.top = 10;
    phone.size = CGSizeMake(120, 20);
    [self addSubview:phone];
    _phoneLa = phone;
    
    CALayer *addLayer = [CALayer layer];
    addLayer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"adressback"].CGImage);
    addLayer.frame = CGRectMake(15, titleLabel.bottom + 10, 15, 18);
    [self.layer addSublayer:addLayer];
    
    YYLabel *address = [YYLabel new];
    address.font = kFONT_TITLE(16);
    address.textColor = [UIColor blackColor];
    address.left = addLayer.right +5;
    address.top = titleLabel.bottom + 5;
    address.size = CGSizeMake(kWindowW - (addLayer.right + 5) - 30, 35);
    address.numberOfLines = 0;
    [self addSubview:address];
    _addressLa = address;
    
    if (_isHaveTap) {
        CALayer *rightLayer = [CALayer layer];
        rightLayer.contents = (__bridge id _Nullable)([UIImage imageNamed:rightBtnImg].CGImage);
        rightLayer.frame = CGRectMake(kWindowW - 13 - 15 , self.height / 2.0 - 11.5, 13, 23);
        [self.layer addSublayer:rightLayer];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tagGestureMethod)];
        [self addGestureRecognizer:tap];
    }
}

- (void)setAddressModel:(JAddressModel *)addressModel
{
    _addressModel = addressModel;
    _nameLa.text = _addressModel.FirstName;
    _phoneLa.text = _addressModel.PhoneNumber;
    _addressLa.text = _addressModel.FullAddress;
}

- (void)tagGestureMethod
{
    if (_allAddressBlock) {
        _allAddressBlock();
    }
}

@end
